//
// Created by shirley on 2024/12/26.
//

#include <cmath>

#include "RBF_function.h"

double RBF_function::weights(const double& distance)
{
    if (function_ == "TPS")
    {
        if (distance == 0.0)
            return 0.0;
        return distance * distance * log(distance);
    }
    else if (function_ == "Gaussian")
    {
        double epsilon = 0.002;
        //printf("weight:  %lf,  distance:  %lf\n",exp(-(epsilon * distance) * (epsilon * distance)), distance);
        return exp(-(epsilon * distance) * (epsilon * distance));
    }
    else if (function_ == "IMBQ")
    {
        double radius_ = 0.001;
        //printf("weight:  %lf,  distance:  %lf\n",exp(-(epsilon * distance) * (epsilon * distance)), distance);
        // return 1/sqrt(distance * distance + radius_*radius_);
        return 1/hypot(distance,radius_);
    }
    else
    {
        printf("Currently, RBF radial basis functions only support TPS、IMBQ and Gaussian！\n");
        exit(1);
    }
}

